﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class Admin_ucControl_ucDVKH : System.Web.UI.UserControl
{
    DVKhachhangDAO dvkhDAO = new DVKhachhangDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            DVKhachhang dvkh = new DVKhachhang();
            dvkh.TieuDe = txtTieuDe.Text.Trim();
            dvkh.NoiDung = FCKeditor1.Value;

            string path = Server.MapPath("~\\Admin\\img\\Items\\");
            string filename = fileUp.FileName;
            if (System.IO.File.Exists(path + filename))
            {

                filename = DateTime.Now.ToString("mm") + "_" + DateTime.Now.ToString("ss") + "_" + filename;
            }
            else
            {
                filename = filename.ToString();
            }
            fileUp.SaveAs(path + filename);

            dvkh.ImageURL = filename;

            string id = Request.QueryString["id"];
            if (id == null || id == "")
            {
                dvkhDAO.InsDVKH(dvkh, 1);
            }
            else
            {
                dvkh.IDDVKH = Global.ConvertToInt(id);
                dvkhDAO.InsDVKH(dvkh, 2);
            }

            flag = true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        if (flag)
        {
            Response.Redirect("~/Admin/DSKhachHang.aspx");
        }
    }
}